package com.msos.dao.phoneAddDao;

import com.msos.model.customer.Customer;
import com.msos.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class phoneAddDao {
    public Integer addPhone(Customer customer) throws SQLException {
        String sql="INSERT into customer(username,gender,idCard,cardType,phone,balance,registDate,enabled,mid,password) VALUES(?,?,?,?,?,?,?,?,?,?)";
        Connection con = DBUtils.getCon();
        Date date=new Date();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy--MM--dd:HH--mm--ss");
        String day=simpleDateFormat.format(date);
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setString(1,customer.getUsername());
        ps.setString(2,customer.getGender());
        ps.setString(3,customer.getIdCard());
        ps.setString(4,customer.getCardType());
        ps.setString(5,customer.getPhone());
        ps.setDouble(6,0);
        ps.setString(7,day);
        ps.setBoolean(8,customer.getEnabled());
        ps.setInt(9,customer.getMid());
        ps.setString(10,customer.getPassword());
        Integer r1=ps.executeUpdate();
        DBUtils.close(ps);
        //
        // return queryRunner.execute("INSERT into message(sephone,acphone,content,sendDate,enabled) VALUES(?,?,?,?,?)",new BeanHandler<>(Customer.class),sePhoNumber,acPhoNumber,msg,day,enabled);
        return r1;
    }
}
